package com.cn.qgx428.lazydiary.extension

import android.view.View
import android.widget.TextView
import android.widget.Toast
import com.cn.qgx428.lazydiary.APP
import com.cn.qgx428.lazydiary.Utils.qiniuUtils.FormatUtils
import java.text.SimpleDateFormat
import java.util.*

/**
 * Created by qinguanxiong on 2018/1/16.
 */

/**
 * 时间扩展
 */
fun Calendar.getCurrentDay(): String {
    val index = get(Calendar.DAY_OF_WEEK)
    var day = ""
    when(index){
        1 -> day = "星期一"
        2 -> day = "星期二"
        3 -> day = "星期三"
        4 -> day = "星期四"
        5 -> day = "星期五"
        6 -> day = "星期六"
        else -> day = "星期天"
    }
    return day
}

fun Calendar.getCurrenMouthWidthYear(): String{
    val mouth = get(Calendar.MONTH) + 1
    var year = get(Calendar.YEAR)

    return FormatUtils.timePatch(year) + "年" + FormatUtils.timePatch(mouth) + "月"
}

fun Calendar.getCurrenMouth():String {
    val mouth = get(Calendar.MONTH) + 1
    return mouth.toString() + "月"
}

fun Calendar.getCurrenTimePrecise(): String{
    val year = get(Calendar.YEAR)
    val mouth = get(Calendar.MONTH) + 1
    val day = get(Calendar.DAY_OF_MONTH)
    val hour = get(Calendar.HOUR_OF_DAY)
    val minute = get(Calendar.MINUTE)
    val seconde = get(Calendar.SECOND)

    return year.toString() + "年" + FormatUtils.timePatch(mouth) + "月" +
            FormatUtils.timePatch(day) + "日" + hour.toString() + "时" +
            minute.toString() + "分" + seconde.toString()
}

fun Calendar.getCurrenDayOfYear(): String{
    val year = get(Calendar.YEAR)
    val mouth = get(Calendar.MONTH) + 1
    val day = get(Calendar.DAY_OF_MONTH)

    return year.toString() + "年" + FormatUtils.timePatch(mouth) + "月" +
            FormatUtils.timePatch(day) + "日"
}


/***********View 扩展***********/

/**
 * 切换可见度
 */
fun View.switchVisible(){
    if (this.visibility == View.GONE){
        this.visibility = View.VISIBLE
    }else
        this.visibility = View.GONE
}

